package com.angel.controller;

import com.angel.bean.Employee;
import com.angel.bean.Feedback;
import com.angel.service.FeedbackService;
import com.angel.utils.AdminUserUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description :
 * InitVersion : 1.0
 * CreateTime :  2018/12/17 0:36
 *
 * @author : Rabit
 * @version 1.0
 */
@Controller
@RequestMapping("/feed")
public class FeedBackController {
    @Autowired
    private FeedbackService feedbackService;

    @RequestMapping("/page")
    public String getpage(@RequestParam(value = "pn", defaultValue = "1") String pn, Model model, HttpSession session){
        Employee et = AdminUserUtils.getPrincipal().getEmployee();
        Feedback feedback  = new Feedback();
        if (et.getEmTypeId() > 2){
            feedback.setBrid(et.getBranchesId());
        }
        int pageNo = 1;
        try {
            pageNo = Integer.valueOf(pn);
        } catch (Exception e) {

        }
        PageHelper.startPage(pageNo, 5); //传入当前页
        List<Feedback> list =feedbackService.getAllFeedBack(feedback);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo", pageInfo);
        return "feedback";
    }


    @RequestMapping("/update")
    @ResponseBody
    public Map update(Feedback feedback){
        Map map  = new HashMap();
        map.put("success",false);
        int flag = feedbackService.updateByPrimaryKeySelective(feedback);
        if (flag != 0){
            map.put("success",true);
        }
       return map;
    }
}
